package com.flyqiu.flow.api.script;

import com.alibaba.fastjson2.JSONArray;

import javax.el.ELContext;
import javax.el.ELResolver;
import java.beans.FeatureDescriptor;
import java.util.Iterator;

public class JSONArrayElResolver extends ELResolver {

    @Override
    public Class<?> getCommonPropertyType(ELContext context, Object base) {
        return null;
    }


    @Override
    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
        return null;
    }

    @Override
    public Class<?> getType(ELContext context, Object base, Object property) {
        return null;
    }


    @Override
    public Object getValue(ELContext context, Object base, Object property) {
        if (base == null) return null;
        if (!(base instanceof JSONArray)) {
            return null;
        }
        int index = Integer.parseInt((String) property);
        return ((JSONArray) base).getJSONArray(index);
    }

    @Override
    public boolean isReadOnly(ELContext context, Object base, Object property) {
        return false;
    }


    @Override
    public void setValue(ELContext context, Object base, Object property, Object value) {

    }
}
